package com.hdsx.restful.glzt.structure.sfz.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.esri.arcgis.geometry.IGeometry;
import com.hdsx.ao.base.BaseOpearte;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Znode;
import com.hdsx.restful.glzt.structure.ql.bean.IntValueName;
import com.hdsx.restful.glzt.structure.ql.bean.StatisticalResult;
import com.hdsx.restful.glzt.structure.sfz.bean.Sfz;
import com.hdsx.restful.glzt.structure.sfz.mapper.SfzMapper;
import com.hdsx.restful.glzt.structure.sfz.service.SfzServer;
import com.hdsx.restful.util.Dao;
/**
 * sfzServer实现类
 *
 */
@Service
public class SfzServerImpl  extends BaseOpearte<Sfz>  implements SfzServer {

	public SfzServerImpl() {
		super("GIS_SFZ");
	}

	@Resource(name="sfzMapper")
	private SfzMapper mapper;

	@Override
	public Sfz getById(String id) {
		return mapper.queryOne(id);
	}

	@Override
	public boolean addSfz(Sfz sfz) {
		return mapper.add(sfz)>0;
	}

	@Override
	public boolean updateSfz(Sfz sfz) {
		return mapper.update(sfz)>0;
	}

	@Override
	public boolean deleteById(String id) {
		return mapper.delete(id)>0;
	}

	@Override
	public int queryCount(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		return mapper.selectCount(parameter);
	}
	@Override
	public List<Sfz> queryList(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name,int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		parameter.put("begin", begin);
		parameter.put("end", end);
		List<Sfz> lists=mapper.selectList(parameter);
		return lists;
	}

	@Override
	public Sfz getOne(String sfzbm) {
		return mapper.queryOne(sfzbm);
	}

	@Override
	public int querySfzCountXzqhbm(String xzqhbm) {
		// TODO Auto-generated method stub
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		return mapper.countByXzqhbm(parameter);
	}

	@Override
	public List<Sfz> getListByXzqhbm(String xzqhbm, int begin, int end) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByXzqhbm(parameter);
	}

	@Override
	public List<Sfz> getListByLxbm(String lxbm, int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByLxbm(parameter);
	}

	@Override
	public int querySfzCountByLxbm(String lxbm) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		return mapper.countByLxbm(parameter);
	}

	@Override
	public List<Dao> getShapeById(String id) {

		Sfz sfz = mapper.getShapeById(id);
		IGeometry shape=selectShape("ID='"+id+"'");
		sfz.setShape(shape);
		List<Dao> lists=new ArrayList<Dao>();
		lists.add(new Dao("收费站名称",sfz.getSfzmc(),sfz.getPtx(),sfz.getPty()));
		lists.add(new Dao("收费站编码",sfz.getSfzbm()));
		lists.add(new Dao("所在路线",sfz.getLxbm()));
		lists.add(new Dao("桩号",sfz.getZh()));
		lists.add(new Dao("收费站类型",sfz.getSfzlx()));
		return lists;
	}
	@Override
	public StatisticalResult countByParameter(Map<String,Object> map) {
		List<IntValueName> serieSfzata = mapper.countTotalByParameter(map);
		List<String> legendData = mapper.selectClassify(map);
		StatisticalResult sr = new StatisticalResult();
		sr.setChartsText("收费站统计");
		sr.setSeriesData(serieSfzata);
		sr.setLegendData(legendData);
		return sr;
	}
	@Override
	public List<Znode> sfzNode() {
		List<Znode> sfzNode = mapper.sfzNode();
		return sfzNode;
	}

	@Override
	public List<Sfz> queryListByParam(String lxbm, String lxmc,	String sfzmc, int sfzlx, int page, int rows) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm",lxbm);
		parameter.put("lxmc",lxmc);
		parameter.put("sfzmc",sfzmc);
		parameter.put("sfzlx",sfzlx);
		parameter.put("begin",page);
		parameter.put("end",rows);
		List<Sfz> lists=mapper.queryListByParam(parameter);
		for(Sfz sfz:lists){
			sfz.setShape(selectShape("ID='"+sfz.getId()+"'"));
		}
		return lists;
	}

	@Override
	public List<Sfz> queryListById(String id) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("id",id);
		List<Sfz> lists=mapper.queryListById(parameter);
		for(Sfz sfz:lists){
			sfz.setShape(selectShape("ID='"+id+"'"));
		}
		return lists;
	}

	@Override
	public int queryCountByParam(String lxbm, String lxmc, String sfzmc,
			int sfzlx) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm",lxbm);
		parameter.put("lxmc",lxmc);
		parameter.put("sfzmc",sfzmc);
		parameter.put("sfzlx",sfzlx);
		return mapper.queryCountByParam(parameter);
	}
	
	 @Override
	 public int countTotal(Map<String, Object> map){
		 return mapper.countTotal(map);
	 }
	 
	 @Override
	 public List<Sfz> listAll(String lxbm,String xzqhbm,String sxxfx,Double qdzh,
			Double zdzh,String name) {
		return mapper.listAll(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name);
	 }
	 @Override
	public Sfz queryById(String id) {
			return mapper.selectById(id);
	}
	/**
	 * 分类细节
	 */
	@Override
	public List<Sfz> detail(Map<String, Object> map){
		return mapper.detail(map);
	}
	@Override
	public int countDetail(Map<String, Object> map) {
		return  mapper.countDetail(map);
	}
	@Override
	public List<String> selectName(String name){
		return mapper.selectName(name);
	}
}
